home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 3.9 KB | 154 lines |
- import java.awt.Frame;
- import java.io.File;
- import java.util.Vector;
-
- import com.apple.mrj.MRJOSType;
- import com.apple.mrj.macos.toolbox.ApplicationEventProxy;
- import com.apple.mrj.macos.toolbox.ApplicationEventListener;
-
- /**
- * This is a simple example of some of the features of the MRJ Toolkit.
- * The CreatorChanger class will recursively traverse a folder hierarchy
- * dropped on it and change all files of type 'TEXT' to have a creator
- * of 'SNJ2' (Symantec's Visual Cafe 2.0).
- * @author Levi Brown
- * @author Apple Worldwide Developer Technical Support
- * @author Apple Computer Inc.
- * @version 1.0 10/28/1998
- */
- public class CreatorChanger extends Frame implements ApplicationEventListener
- {
- //The creator to change the file to.
- static final MRJOSType defaultCreator = new MRJOSType("SNJ2");
- //The type of file to change creator for.
- static final MRJOSType defaultType = new MRJOSType("TEXT");
-
- //---------- ApplicationEventListener Implementation ----------//
- /**
- * Handles displaying about information for the application.
- * This routine gets called by the MRJToolkit when the
- * application should display about info.
- */
- public void aboutApplication()
- {
- (new AboutCCDialog(this)).setVisible(true);
- }
-
- /**
- * This method gets called when the application is opened via double-click.
- */
- public void openApplication()
- {
- }
-
- /**
- * Handles opening of files dropped on the application.
- * This routine gets called by MRJ for each drop batch.
- */
- public void openDocuments(java.io.File[] files)
- {
- BatchJob batchJob = new BatchJob(this, batchAction, files);
- jobs.addElement(batchJob);
- batchJob.processBatch(defaultType, defaultCreator);
- }
-
- /**
- * Handles printing of files for this application.
- * This routine gets called by MRJ for each printing batch.
- */
- public void printDocuments(java.io.File[] files)
- {
- }
-
- /**
- * Handles quitting the application.
- * This routine gets called by the MRJToolkit when the
- * application should quit.
- */
- public void quitApplication()
- {
- //Exit with success.
- System.exit(0);
- }
- //---------- End ApplicationEventListener Implementation ----------//
-
-
- public void handleOpenFile(String[] files, String type, String creator)
- {
- MRJOSType myType;
- MRJOSType myCreator;
- try
- {
- myType = new MRJOSType(type);
- myCreator = new MRJOSType(creator);
- }
- catch (Exception exc)
- {
- System.err.println("handleOpenFile: bad type and/or creator. Using defaults.");
- myType = defaultType;
- myCreator = defaultCreator;
- }
-
- File[] rawFiles = new File[files.length];
-
- for (int i = 0; i < files.length; ++i)
- {
- rawFiles[i] = new File(files[i]);
- }
- BatchJob batchJob = new BatchJob(this, batchAction, rawFiles);
- jobs.addElement(batchJob);
- batchJob.processBatch(myType, myCreator);
- }
-
- /**
- * Constructs a default instance of this class.
- * Registers the new instance with MRJ Toolkit
- * as an open document listener and quit listener.
- */
- public CreatorChanger()
- {
- //Register MRJ handlers
- ApplicationEventProxy.installListener(this);
- //Create a vector to keep track of the jobs
- jobs = new Vector();
- //Create a listener to respond to jobs finishing
- batchAction = new BatchAction();
-
- //{{INIT_CONTROLS
- setLayout(null);
- setBounds(-5000, -5000, 10,10);
- setTitle("Untitled");
- //}}
- //{{INIT_MENUS
- //}}
- }
- //{{DECLARE_CONTROLS
- //}}
- //{{DECLARE_MENUS
- //}}
-
- /**
- * Entry point for our application.
- * Creates a new instance of this class.
- */
- static public void main(String args[])
- {
- CreatorChanger creatorChanger = new CreatorChanger();
- creatorChanger.setVisible(true);
- }
-
- class BatchAction implements java.awt.event.ActionListener
- {
- public void actionPerformed(java.awt.event.ActionEvent event)
- {
- Object object = event.getSource();
- jobs.removeElement(object);
- if (jobs.size() == 0)
- quitApplication();
- }
- }
-
- protected Vector jobs;
- protected BatchAction batchAction;
- }
-